<?php
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Api\Controller;
use Think\Model;

/**
 * 服务类型控制器
 * @author derek <693472824@qq.com>
 */
class ClassController extends BaseController {
    
    /**
     * 搜索列表
     * @author derek <693472824@qq.com>
     */
    public function index(){
        
        $param = I('param');
        
        $classList = M('Class')->where(array('show_status=1'))->getField('class_id,class_name,emergency');
        
        $classTree = array();
        $map = array();
        
        if(!empty($param)){
            $map['detail_name|kwords'] = array('like', '%'.(string)$param.'%');
        }
        
        $detailList = M('ClassDetail')->where($map)->getField('detail_id,class_id,detail_name,price,unit,emergency,kwords');
        
        if(!empty($detailList)){
            foreach ($detailList as $key=>$val){
                
                if(empty($classTree[$val['class_id']])){
                    
                    $classTree[$val['class_id']]['name'] = $classList[$val['class_id']]['class_name'];
                }
                
                $classTree[$val['class_id']]['detail'][] = $val;
            }
        }
        
        $this->assign('param', $param);
        $this->assign('list', $classTree);
        $this->display();
    }
    
    /**
     * 
     */
    public function viewAction(){
        
        $classID = I('class_id');
        $classID = empty($classID) ? '1' : $classID;
        
        $classTree = D('Blovex4/Class', 'Logic')->getClassTree(0);
        
        $this->assign('class_id', $classID);
        $this->assign('tree', $classTree);
        $this->display();
    }
    
    /**
     * 
     */
    public function detailAction(){
        
        $classID = I('class_id');
        
        $map['class_id'] = $classID;
        
        $detailList = M('ClassDetail')->where($map)->getField('detail_id,class_id,detail_name,price,unit,emergency,kwords');
        
        $this->assign('list', $detailList);
        $this->display();
    }
}
